package com.cosina.game.crystallight.model.profile;

import com.cosina.game.crystallight.dao.ProfileDAOFacade;

public class SkillManager {
	private final Skill[] skills;;
	
	private int skillpoint;
	
	public SkillManager(int[] levels,int skillpoint){
		skills = new Skill[levels.length];
		for(int i=0; i<levels.length; i++){
			skills[i] = new Skill(levels[i]);
		}
		this.skillpoint = skillpoint;
	}
	
	public int getSkillPoint(){
		return skillpoint;
	}
	
	
	public int getLevel(int type){
		return getSkillLevels()[type];
	}
	
	public int[] getSkillLevels(){
		int[] levels = new int[skills.length];
		for(int i=0; i<skills.length; i++){
			levels[i] =  skills[i].getLevel();
		}
		return levels;
	}
	
	public void trySkillUp(int type) {
		Skill skill = skills[type];
		if(skill.hasNextSkillLevel() == false)
			return ;
		int nextLevelPoint = skill.nextNeedSkillPoint();
		
		if(skillpoint < nextLevelPoint )
			return ;
		
		skillpoint -= nextLevelPoint;
	
		skills[type] = new Skill(skill.getLevel() + 1);
		
		ProfileDAOFacade.saveCurrentProfile();
	}

	public void add() {
		skillpoint += 2;
	}
}
